package com.cyt.web.controller.sys;

import com.cyt.base.enums.BusinessType;
import com.cyt.base.enums.OperatorType;
import com.cyt.base.model.dto.ReturnResult;
import com.cyt.sys.aspect.BaseLog;
import com.cyt.sys.model.po.SysLisenceManage;
import com.cyt.sys.model.vo.SysLisenceManageVo;
import com.cyt.sys.service.SysLisenceManageService;
import com.cyt.sys.service.SysVersionService;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;


/**
 * lisence控制层
 *
 * @author dingxu
 * @date 2019-04-03 10:00
 */
@RestController
public class SysLisenceManageController extends SysBaseController {

    @Resource
    private SysLisenceManageService sysLisenceManageService;
    @Resource
    private SysVersionService sysVersionService;

    /**
     * 系统模块统一跳转处理
     *
     * @author dingxu
     * @date 2019-04-03 10:00
     */
    @RequestMapping("/sys/baseLisenceManage/*")
    public Model goPage(Model model) {
        return model;
    }

    /**
     * lisence管理分页
     *
     * @param page:当前页面
     * @param limit:页面大小
     * @author dingxu
     * @date 2019-04-03 10:00
     */
    @BaseLog(module = "系统模块", classz = "lisence管理", methods = "分页查询", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/sysLisenceManage/page", method = RequestMethod.POST)
    public ReturnResult page(SysLisenceManageVo sysLisenceManageVo, int limit, int page) {
        ReturnResult returnResult = sysLisenceManageService.page(sysLisenceManageVo, limit, page);
        return returnResult;
    }


    /**
     * 跳转保存/更新页面
     *
     * @param id 应用主键
     * @author dingxu
     * @date 2019-04-03 10:00
     */
    @RequestMapping(value = "/sysLisenceManage/getEdit", method = RequestMethod.GET)
    public ModelAndView getEdit(String id) {
        ModelAndView view = new ModelAndView("/sys/baseLisenceManage/baseLisenceManageEdit");
        if (id != null && !"".equals(id)) {
            SysLisenceManage baseLisenceManage = sysLisenceManageService.selectByPrimaryKey(id);
            view.addObject(baseLisenceManage);
        }
        return view;
    }

    /**
     * 保存/更新lisence数据
     *
     * @param sysLisenceManageVo 对象
     * @author dingxu
     * @date 2019-04-03 10:00
     */
    @BaseLog(module = "系统模块", classz = "lisence管理", methods = "保存/更新应用", businessType = BusinessType.INSERT, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/sysLisenceManage/addOrUpdate", method = RequestMethod.POST)
    public ReturnResult addOrUpdate(SysLisenceManageVo sysLisenceManageVo) {
        ReturnResult result = sysLisenceManageService.addOrUpdate(sysLisenceManageVo);
        return result;
    }

    /**
     * 删除lisence数据
     *
     * @param id 主键id数组字符串集
     * @author dingxu
     * @date 2019-04-03 10:00
     */
    @BaseLog(module = "系统模块", classz = "lisence管理", methods = "删除应用", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/sysLisenceManage/delete", method = RequestMethod.GET)
    public ReturnResult delete(String id) {
        return sysLisenceManageService.delete(id);
    }

    /**
     * 菜单加密
     *
     * @param id
     * @return
     * @author dingxu
     */
    @BaseLog(module = "系统模块", classz = "lisence管理", methods = "数据加密", businessType = BusinessType.UPDATE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/sysVersion/encordVersion", method = RequestMethod.GET)
    public ReturnResult encordVersion(String id) {
        return sysVersionService.encordBaseVersion(id);
    }

    /**
     * 对lisence进行加密处理
     *
     * @param id lisence id
     * @author sunli
     * @date 2019-04-16
     */
    @RequestMapping(value = "/sysLisenceManage/encordLisence", method = RequestMethod.GET)
    public ReturnResult encordLisence(String id) {
        return sysLisenceManageService.encordBaseLisence(id);
    }
}
